package com.ohuang.wallpapermanager.screen

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.ohuang.wallpapermanager.R
import com.ohuang.wallpapermanager.compose.clickableSafe
import com.ohuang.wallpapermanager.compose.dp2sp
import com.ohuang.wallpapermanager.compose.onClickSafe
import com.ohuang.wallpapermanager.screen.Destination.EditWallPaperInfo
import com.ohuang.wallpapermanager.screen.Destination.SettingWallPaper
import com.ohuang.wallpapermanager.screen.Destination.WallPaperList

@Composable
fun MainScreen() {
    val rememberNavController = rememberNavController()
    NavHost(navController = rememberNavController, startDestination = Destination.HOME) {
        composable(Destination.HOME) {
            HomeScreen(rememberNavController)
        }

        SettingWallPaper { isLock ->
            SettingWallPaperScreen(isLockWall = isLock!!, goBack = {
                rememberNavController.popBackStack()
            })
        }

        WallPaperList{ isLock ->
            WallPaperListScreen(isLockWall = isLock!!, goBack = {
                rememberNavController.popBackStack()
            }, navController = rememberNavController)
        }

        EditWallPaperInfo{isLock ,id->
            EditWallPaperInfoScreen(isLockWall = isLock!!, id = id!!, goBack = {
                rememberNavController.popBackStack()
            })
        }

        composable(Destination.SETTINGS) {
            SettingScreen(goBack = {
                rememberNavController.popBackStack()
            })
        }


    }

}

@Composable
fun TopBar(
    modifier: Modifier = Modifier, title: String, backClick: () -> Unit
) {
    Box(modifier = modifier
        .fillMaxWidth()
        .padding(10.dp)) {
        Image(modifier = Modifier
            .align(Alignment.CenterStart)
            .size(30.dp)
            .clickableSafe {
                backClick()
            }
            .padding(start = 10.dp),
            painter = painterResource(id = R.drawable.iv_back),
            contentDescription = "返回")

        Text(
            text = title,
            modifier = Modifier.align(Alignment.Center),
            color = Color.Black,
            fontSize = 18.dp2sp()
        )
    }
}

@Composable
fun TopTitleBar(
    modifier: Modifier = Modifier, title: String
) {
    Box(modifier = modifier
        .fillMaxWidth()
        .height(50.dp)) {
        Text(
            text = title,
            modifier = Modifier.align(Alignment.Center),
            color = Color.Black,
            fontSize = 18.dp2sp()
        )
    }
}